
using System;
using System.Collections;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
 // ERROR: Not supported in C#: OptionDeclaration
namespace NCS_CS
{
	internal partial class frmUser : System.Windows.Forms.Form
	{

		private void Command1_Click(System.Object eventSender, System.EventArgs eventArgs)
		{
			if (ModMain.getsession().IsDirty()) {
				ModMain.getsession().Flush();
				//Call gDb.myLoadmethodByid((user1.mname), (user1.methodid))
			}
			this.Visible = false;
		}

		private void frmUser_Load(System.Object eventSender, System.EventArgs eventArgs)
		{
			rebind();
		}
		public void rebind()
		{
			IList o = null;
			o = ModMain.getsession().CreateCriteria(typeof(NCS.muser)).List();
			//o = session.CreateSQLQuery("select mname,mpassword from muser", "", GetType(NCS.muser)).List()
			//Debug.Print(CStr(o.Count))
            //NCS.muser u = null;
			NCS.muser u1 = null;
			NCS.muser u2 = null;
			foreach (NCS.muser u in o) {
                //u = u_loopVariable;
				if (u.mname == "general") {
					u1 = u;
				}
				if (u.mname == "system") {
					u2 = u;
				}
			}
			if ((u1 != null)) {
				o.Remove(u1);
			}

			if ((u2 != null)) {
				o.Remove(u2);
			}
			this.DataGrid1.DataSource = o;
			//.GetEnumerator()


		}
		private void Button2_Click(System.Object sender, System.EventArgs e)
		{
			if (ModMain.getsession().IsDirty()) {
				ModMain.getsession().Flush();
				//Call gDb.myLoadmethodByid((user1.mname), (user1.methodid))
			}
		}

		private void Button3_Click(System.Object sender, System.EventArgs e)
		{
			Button3.Enabled = false;
			object id = null;
			id = this.DataGrid1.CurrentRow.DataBoundItem;
			ModMain.getsession().Delete(id);
			ModMain.getsession().Flush();
			rebind();
			Button3.Enabled = true;
		}

		private void Button1_Click(System.Object sender, System.EventArgs e)
		{
			Button1.Enabled = false;
			NCS.muser m = new NCS.muser();
			if (this.TextBox1.Text != "general" & this.TextBox1.Text != "system") {
				m.mname = this.TextBox1.Text;
				m.mpassword = this.TextBox2.Text;
				ModMain.getsession().Save(m);
				ModMain.getsession().Flush();
				rebind();
			}
			Button1.Enabled = true;
		}
	}
}
